const TrumpCoin = artifacts.require("TrumpCoin");

module.exports = async function (deployer, network, accounts) {
  try {
    // 拿到部署者的账户
    const from = accounts && accounts.length ? accounts[0] : undefined;

    // 输出当前网络与账户信息
    console.log(`Deploying TrumpCoin to network: ${network}`);
    if (from) console.log(`Deployer account: ${from}`);

    // 获取当前 gasPrice 作为默认值（可按需覆盖）
    const gasPrice = await web3.eth.getGasPrice();
    console.log(`Using gasPrice: ${gasPrice}`);

    // 执行部署（无构造参数），可传入 from / gasPrice 等选项
    await deployer.deploy(TrumpCoin, { from, gasPrice });

    // 部署完成后，输出地址与简单校验信息
    const instance = await TrumpCoin.deployed();
    console.log(`TrumpCoin deployed at: ${instance.address}`);

    const totalSupply = await instance.totalSupply();
    console.log(`Total supply: ${totalSupply.toString()}`);

    if (from) {
      const deployerBalance = await instance.balanceOf(from);
      console.log(`Deployer balance: ${deployerBalance.toString()}`);
    }
  } catch (error) {
    console.error("Deployment failed:", error);
    throw error;
  }
};